

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Petaframe.Logging
{
    /// <summary>
    /// A LogEntryFormatter subclass that works like the string.Format() method.
    /// Instead of using an index for the parameter, use certain reserved names, such as:
    /// application
    /// machine
    /// category
    /// severity
    /// timestamp
    /// message
    /// eg. "{timestamp:G}..{severity}..{message}"
    /// </summary>
    public class LogEntryFormatStringFormatter : LogEntryFormatter
    {
        /// <summary>
        /// The string representing the format of the log strings as they should be output to the log
        /// </summary>
        public new readonly string FormatString;

        /// <summary>
        /// Instantiate a new instance of LogEntryFormatStringFormatter
        /// </summary>
        /// <param name="aFormatString">The format string</param>
        /// <param name="aLoggingErrorHandler">A delegate used to trigger the LoggingError event in a Logger</param>
        public LogEntryFormatStringFormatter(string aFormatString, Logger.LoggingErrorHandler aLoggingErrorHandler) : base(aLoggingErrorHandler)
        {
            FormatString = aFormatString;
        }

        /// <summary>
        /// return a LogEntry formatted as a string
        /// </summary>
        /// <param name="aLogEntry">The LogEntry to log</param>
        /// <returns>a string formatted appropriately</returns>
        protected internal override string AsString(LogEntry aLogEntry)
        {
            return LogEntryRegexMatchReplacer.Replace(FormatString, aLogEntry, LoggingErrorHandler);
        }

    }
}
